package com.vincent.template.controller.manage;

import com.vincent.template.dto.sys.user.UserInfoDto;
import com.vincent.template.dto.sys.user.UserUpdateDto;
import com.vincent.template.service.logic.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Vincent Wang
 * @date 2021/3/25 15:59
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/manage/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("批量查询用户信息")
    @GetMapping
    public List<UserInfoDto> findUsers() {
        return userService.findUsers();
    }

    @ApiOperation("根据用户Id查询用户信息")
    @GetMapping("/{id}")
    public UserInfoDto findUserInfo(@PathVariable("id") String id) {
        return userService.findUserById(id);
    }

    @ApiOperation("更新用户信息")
    @PutMapping("/{id}/update")
    public boolean updateInfo(@PathVariable("id") String id,
                              @Validated @RequestBody UserUpdateDto updateDto) {
        return userService.updateInfo(id, updateDto);
    }

    @ApiOperation("注销用户")
    @DeleteMapping("/{id}/cancel")
    public boolean selfCancel(@PathVariable("id") String id) {
        return userService.adminCancel(id);
    }
}
